//
//  AfterSaleCell.swift
//  Eternity
//
//  Created by cll12_12 on 2016/12/27.
//  Copyright © 2016年 ZhengWei. All rights reserved.
//

import UIKit

class AfterSaleCell: UITableViewCell {

    // MARK: - life cycle
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initBaseLayout()
        layoutPageSubviews()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - private method
    func initBaseLayout() {
        self.addSubview(topBackView)
        topBackView.addSubview(orderNumLabel)
        topBackView.addSubview(statusLabel)
        topBackView.addSubview(topLine)
        self.addSubview(middleBackView)
        middleBackView.addSubview(iconImageView)
        middleBackView.addSubview(productLabel)
        middleBackView.addSubview(netContentLabel)
        middleBackView.addSubview(priceLabel)
        middleBackView.addSubview(bottomLine)
        self.addSubview(bottomBackView)
        bottomBackView.addSubview(refundAmountLabel)
        bottomBackView.addSubview(checkBtn)
    }
    
    func layoutPageSubviews() {
        topBackView.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(0)
            make.right.equalTo(self).offset(0)
            make.top.equalTo(self).offset(0)
            make.height.equalTo(40)
        }
        
        orderNumLabel.snp.makeConstraints { (make) in
            make.left.equalTo(topBackView).offset(9)
            make.centerY.equalTo(topBackView)
            make.width.equalTo(207)
            make.height.equalTo(18)
        }
        
        statusLabel.snp.makeConstraints { (make) in
            make.right.equalTo(topBackView).offset(-14)
            make.centerY.equalTo(topBackView)
            make.width.equalTo(59)
            make.height.equalTo(17)
        }
        
        topLine.snp.makeConstraints { (make) in
            make.left.equalTo(topBackView).offset(14)
            make.bottom.equalTo(topBackView).offset(0)
            make.right.equalTo(topBackView).offset(0)
            make.height.equalTo(1)
        }
        
        middleBackView.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(0)
            make.top.equalTo(topLine.snp.bottom).offset(0)
            make.right.equalTo(self).offset(0)
            make.height.equalTo(142)
        }
        
        iconImageView.snp.makeConstraints { (make) in
            make.left.equalTo(middleBackView).offset(14)
            make.centerY.equalTo(middleBackView)
            make.width.height.equalTo(100)
        }
        
        productLabel.snp.makeConstraints { (make) in
            make.left.equalTo(iconImageView.snp.right).offset(14)
            make.top.equalTo(middleBackView).offset(35)
            make.width.equalTo(100)
            make.height.equalTo(14)
        }
        
        netContentLabel.snp.makeConstraints { (make) in
            make.left.equalTo(iconImageView.snp.right).offset(14)
            make.top.equalTo(productLabel.snp.bottom).offset(10)
            make.width.equalTo(100)
            make.height.equalTo(12)
        }
        
        priceLabel.snp.makeConstraints { (make) in
            make.left.equalTo(iconImageView.snp.right).offset(14)
            make.top.equalTo(netContentLabel.snp.bottom).offset(32)
            make.width.equalTo(100)
            make.height.equalTo(14)
        }
        
        bottomLine.snp.makeConstraints { (make) in
            make.left.equalTo(middleBackView).offset(14)
            make.bottom.equalTo(middleBackView.snp.bottom).offset(0)
            make.right.equalTo(middleBackView).offset(0)
            make.height.equalTo(1)
        }
        
        bottomBackView.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(0)
            make.top.equalTo(middleBackView.snp.bottom).offset(0)
            make.right.equalTo(self).offset(0)
            make.height.equalTo(49)
        }
        
        refundAmountLabel.snp.makeConstraints { (make) in
            make.left.equalTo(bottomBackView).offset(14)
            make.centerY.equalTo(bottomBackView)
            make.width.equalTo(120)
            make.height.equalTo(14)
        }
        
        checkBtn.snp.makeConstraints { (make) in
            make.right.equalTo(bottomBackView).offset(-14)
            make.centerY.equalTo(bottomBackView)
            make.width.equalTo(84)
            make.height.equalTo(32)
        }
    }
    
    func configUI() {
        orderNumLabel.text = "订单号：HM16081616060001"
        statusLabel.text = "退款成功"
        productLabel.text = "苦橙收敛调理液"
        netContentLabel.text = "净含量：200ml"
        priceLabel.text = "￥335.00 x 1"
        refundAmountLabel.text = "退款金额：￥127.00"
        checkBtn.setTitle("退款明细", for: .normal)
        iconImageView.sd_setImage(with: URL(string: "http://img15.3lian.com/2015/h1/57/d/61.jpg"), placeholderImage: UIImage(named: "def_100x100"))
    }
    
    // MARK: - setters and getters
    var _topBackView: UIView!
    var topBackView: UIView {
        if _topBackView == nil {
            _topBackView = UIView()
            _topBackView.backgroundColor = UIColor.white
        }
        return _topBackView
    }
    
    var _orderNumLabel: UILabel!
    var orderNumLabel: UILabel {
        if _orderNumLabel == nil {
            _orderNumLabel = UILabel()
            _orderNumLabel.font = UIFont(name: "PingFangSC-Regular", size: 14)
            _orderNumLabel.textColor = UIColor(hexString: "#666666")
        }
        return _orderNumLabel
    }
    
    var _statusLabel: UILabel!
    var statusLabel: UILabel {
        if _statusLabel == nil {
            _statusLabel = UILabel()
            _statusLabel = UILabel()
            _statusLabel.font = UIFont(name: "PingFangSC-Regular", size: 14)
            _statusLabel.textColor = UIColor(hexString: "#000000")
            _statusLabel.textAlignment = .right
        }
        return _statusLabel
    }
    
    var _topLine: UIView!
    var topLine: UIView {
        if _topLine == nil {
            _topLine = UIView()
            _topLine.backgroundColor = UIColor(hexString: "#DDDDDD")
        }
        return _topLine
    }
    
    var _middleBackView: UIView!
    var middleBackView: UIView {
        if _middleBackView == nil {
            _middleBackView = UIView()
            _middleBackView.backgroundColor = UIColor.white
        }
        return _middleBackView
    }
    
    var _iconImageView: UIImageView!
    var iconImageView: UIImageView {
        if _iconImageView == nil {
            _iconImageView = UIImageView()
        }
        return _iconImageView
    }
    
    var _productLabel: UILabel!
    var productLabel: UILabel {
        if _productLabel == nil {
            _productLabel = UILabel()
            _productLabel.font = UIFont(name: "PingFangSC-Regular", size: 14)
            _productLabel.textColor = UIColor(hexString: "#252525")
        }
        return _productLabel
    }
    
    var _netContentLabel: UILabel!
    var netContentLabel: UILabel {
        if _netContentLabel == nil {
            _netContentLabel = UILabel()
            _netContentLabel.font = UIFont(name: "PingFangSC-Light", size: 12)
            _netContentLabel.textColor = UIColor(hexString: "#666666")
        }
        return _netContentLabel
    }
    
    var _priceLabel: UILabel!
    var priceLabel: UILabel {
        if _priceLabel == nil {
            _priceLabel = UILabel()
            _priceLabel.font = UIFont(name: "PingFangSC-Regular", size: 14)
            _priceLabel.textColor = UIColor(hexString: "#252525")
        }
        return _priceLabel
    }
    
    var _bottomBackView: UIView!
    var bottomBackView: UIView {
        if _bottomBackView == nil {
            _bottomBackView = UIView()
            _bottomBackView.backgroundColor = UIColor.white
        }
        return _bottomBackView
    }
    
    var _bottomLine: UIView!
    var bottomLine: UIView {
        if _bottomLine == nil {
            _bottomLine = UIView()
            _bottomLine.backgroundColor = UIColor(hexString: "#DDDDDD")
        }
        return _bottomLine
    }
    
    var _refundAmountLabel: UILabel!
    var refundAmountLabel: UILabel {
        if _refundAmountLabel == nil {
            _refundAmountLabel = UILabel()
            _refundAmountLabel.font = UIFont(name: "PingFangSC-Regular", size: 12)
            _refundAmountLabel.textColor = UIColor(hexString: "#000000")
        }
        return _refundAmountLabel
    }
    
    var _checkBtn: UIButton!
    var checkBtn: UIButton {
        if _checkBtn == nil {
            _checkBtn = UIButton()
            _checkBtn.backgroundColor = UIColor(hexString: "#FFFFFF")
            _checkBtn.setTitleColor(UIColor(hexString: "#252525"), for: .normal)
            _checkBtn.titleLabel?.font = UIFont(name: "PingFang-SC-Regular", size: 12)
            _checkBtn.layer.borderColor = UIColor(hexString: "#B7B7B7")?.cgColor
            _checkBtn.layer.borderWidth = 0.5
        }
        return _checkBtn
    }

}
